package com.zhima.config;

import lombok.Data;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.boot.context.properties.ConfigurationProperties;


@Data
@ConfigurationProperties("generator")
public class MybatisEmcProperties implements SmartInitializingSingleton {
    private final String baseBir = System.getProperty("user.dir");
    private String url;
    private String username;
    private String password;
    private String generateBaseDirPath = baseBir;
    private String author = System.getenv("USERNAME");
    private PackageInfo packageInfo = new PackageInfo();

    @Override
    public void afterSingletonsInstantiated() {
        if (url.isBlank() || username.isBlank() || password.isBlank()) {
            throw new IllegalArgumentException("数据库地址不得为空");
        }
    }

    @Data
    public class PackageInfo {
        private String parentPackageName = String.format("com.%s", author);
        private String parentModulePackageName = "";
        private String entityPackageName = "entity";
        private String servicePackageName = "service";
        private String serviceImplPackageName = "impl";
        private String mapperPackageName = "mapper";
        private String mapperXmlPackageName = "mapper";
        private String controllerPackageName = "controller";

        public PackageInfo() {
        }
    }
}
